﻿@model Telerik.Web.Mvc.GridModel<HolidayModel>
@using Telerik.Web.Mvc.UI;
@using System.Linq;
@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    //page title
    ViewBag.Title = T("Admin.Configuration.Holidays").Text;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/subsites/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.Configuration.Holidays")
    </div>
</div>

<table class="adminContent">
    <tr>
        <td>
            @(Html.Telerik().Grid(Model.Data)
                    .Name("holidays-grid")
                    .DataKeys(x =>
                    {
                        x.Add(y => y.Id).RouteKey("Id");
                    })
                    .Columns(columns =>
                    {
                        columns.Bound(x => x.Name).EditorTemplateName("String").Width(150);
                        columns.Bound(x => x.Dates).Template(x => 
                                Html.ActionLink(x.Dates, "Dates", new { holidayId = x.Id })
                            )
                            .ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Holiday/Dates") + "?holidayid=<#= Id #>\"><#= Dates #></a>")
                            .ReadOnly()
                            .Width(150);
                        columns.Bound(x => x.StateProvinces).Template(x =>
                                Html.ActionLink(x.StateProvinces, "StateProvinces", new { holidayId = x.Id })
                            )
                            .ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Holiday/StateProvinces") + "?holidayid=<#= Id #>\"><#= StateProvinces #></a>")
                            .ReadOnly()
                            .Width(150);
                        columns.Bound(x => x.CountryCode).EditorTemplateName("String").Width(50);
                        columns.Bound(x => x.Description).EditorTemplateName("String").Width(100);
                        columns.Bound(x => x.DisplayOrder).EditorTemplateName("Int32").Width(50);
                        columns.Command(commands =>
                        {
                            commands.Edit().Text(T("Admin.Common.Edit").Text);
                            commands.Delete().Text(T("Admin.Common.Delete").Text);
                        }).Width(180);

                    })
                    .ToolBar(x => x.Insert())
                    .Editable(x =>
                    {
                        x.Mode(GridEditMode.InLine);
                    })
                    .Filterable()
                    .Pageable(settings => settings.PageSize(gridPageSize).Total(Model.Total).Position(GridPagerPosition.Both))
                    .DataBinding(dataBinding =>
                    {
                        dataBinding.Ajax().Select("List", "Holiday")
                            .Update("Edit", "Holiday")
                            .Delete("Delete", "Holiday")
                            .Insert("Create", "Holiday", new { Id = 0 } );
                    })
                    .EnableCustomBinding(true)
                    .ClientEvents(x => x.OnError("Grid_onError")))
        </td>
    </tr>
</table>
<script type="text/javascript">
    function Grid_onError(e) {
        alert(e.XMLHttpRequest.responseText);
        e.preventDefault();
    }
</script>
